package com.ihelp.rest.mis.users.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.ihelp.rest.base.hibernate4.BaseHibernateDao;
import com.ihelp.rest.mis.pojo.Users;

/**
 * 会员
*      
* 类名称：UsersDao   
* 类描述：     
* 创建时间：2013-3-21 下午02:35:53    
* 备注：   
* @version
 */
@Repository
public class UsersDao extends BaseHibernateDao<Users, String>{

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	/**
	 * 查询家长编码最大的记录
	 * @return
	 */
	public Users queryMaxCode(String adcode){
		return this.unique("from Users a where substr(a.code,0,6)='"+adcode+"' and substr(a.code,7)=(select max(substr(b.code,7)) from Users b where substr(b.code,0,6)='"+adcode+"')");
	}
	
	
	public Users queryUsersByCode(String usercode){
		return this.unique("from Users where code = '"+usercode+"' ");
	}
	
	public int getYHage(String birthday){
		return this.jdbcTemplate.queryForInt("select round((sysdate - to_date('"+birthday+"','yyyy-mm-dd'))/365,0)  from dual ");
	}
	
	public int getCountDay(String begin,String end){
		return this.jdbcTemplate.queryForInt("select round((to_date('"+end+"','yyyy-mm-dd') - to_date('"+begin+"','yyyy-mm-dd')),0)  from dual ");
	}
}
